package com.aegean.MonitorExamSYS.center.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

@Controller("ClearSessionForExaminee")
@Scope("prototype")
public class ClearSessionForExaminee extends ActionSupport implements
		ServletRequestAware {
	private HttpServletRequest request;
	private HttpSession session;
	private boolean success;

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		try {
			String[] deleteSession = { "UnitExamineeForArrangeExaminee",// 删除每一个考点对应的考场对应的考生
					"PositionMapsForArrangeExaminee",// 删除每个考场对应的考生实体
					"ConductionsForExaminee"};// 删除该所有考点资格实体
			for (String string : deleteSession) {
				if (session.getAttribute(string) == null) {
					continue;
				} else {
					session.removeAttribute(string);
				}
			}
			success = true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			success = false;
		}
		return SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;
		this.session = request.getSession();

	}

}
